﻿Imports System.Runtime.Serialization

Namespace Model

    <Serializable()> _
    Public Class Employee
        Implements ISerializable

#Region "Properties"

        Private _code As Integer
        Public Property UniqueCode() As Integer
            Get
                Return _code
            End Get
            Set(ByVal value As Integer)
                _code = value
            End Set
        End Property

        Private _fullName As String
        Public Property FullName() As String
            Get
                Return _fullName
            End Get
            Set(ByVal value As String)
                _fullName = value
            End Set
        End Property

        Private _birth As Date
        Public Property BirthDate() As Date
            Get
                Return _birth
            End Get
            Set(ByVal value As Date)
                _birth = value
            End Set
        End Property

        Private _address As String
        Public Property Address() As String
            Get
                Return _address
            End Get
            Set(ByVal value As String)
                _address = value
            End Set
        End Property

        Private _contactNumber As String
        Public Property ContactNumber() As String
            Get
                Return _contactNumber
            End Get
            Set(ByVal value As String)
                _contactNumber = value
            End Set
        End Property

        Private _cellPhone As String
        Public Property CellPhone() As String
            Get
                Return _cellPhone
            End Get
            Set(ByVal value As String)
                _cellPhone = value
            End Set
        End Property


        Private _update As Date
        Public Property DateChanged() As Date
            Get
                Return _update
            End Get
            Set(ByVal value As Date)
                _update = value
            End Set
        End Property


        Private _valid As Boolean
        Public Property IsValid() As Boolean
            Get
                Return _valid
            End Get
            Set(ByVal value As Boolean)
                _valid = value
            End Set
        End Property

        <NonSerialized()> _
        Private _active As Boolean
        Public Property IsActive() As Boolean
            Get
                Return _active
            End Get
            Set(ByVal value As Boolean)

                _active = value
            End Set
        End Property

#End Region

#Region "Creation"

        Protected Sub New()

        End Sub

        Public Sub New(ByVal info As SerializationInfo, _
                       ByVal context As StreamingContext)
            Me.UniqueCode = info.GetInt32("UniqueCode")
            Me.FullName = info.GetString("FullName")
            Me.BirthDate = info.GetDateTime("BirthDate")
            Me.Address = info.GetString("Address")
            Me.ContactNumber = info.GetString("ContactNumber")
            Me.CellPhone = info.GetString("CellPhone")
            Me.DateChanged = info.GetDateTime("DateChanged")
            Me.IsValid = info.GetBoolean("IsValid")

        End Sub

        Public Sub GetObjectData(ByVal info As SerializationInfo, _
                                 ByVal context As StreamingContext) _
                                 Implements ISerializable.GetObjectData
            info.AddValue("UniqueCode", Me.UniqueCode)
            info.AddValue("FullName", Me.FullName)
            info.AddValue("BirthDate", Me.BirthDate)
            info.AddValue("Address", Me.Address)
            info.AddValue("ContactNumber", Me.ContactNumber)
            info.AddValue("CellPhone", Me.CellPhone)
            info.AddValue("DateChanged", Me.DateChanged)
            info.AddValue("IsValid", Me.IsValid)
        End Sub


        Public Shared Function CreateNewEmployee() As Employee
            Return New Employee()
        End Function

        Public Shared Function CreateEmployee(ByVal code As Integer, _
                                              ByVal fullName As String, _
                                              ByVal birth As Date, _
                                              ByVal address As String, _
                                              ByVal contactNumber As String, _
                                              ByVal cellPhone As String) As Employee
            Dim e As Employee = New Employee()
            With e
                .UniqueCode = code
                .FullName = fullName
                .Address = address
                .ContactNumber = contactNumber
                .CellPhone = cellPhone
                .DateChanged = Date.Today
                .IsValid = True
            End With
            Return e
        End Function

#End Region

#Region "Overriden Object"

        Public Overrides Function GetHashCode() As Integer
            Dim hashCode As Integer = 0
            hashCode += 1000000001 * UniqueCode.GetHashCode()
            hashCode += 1000000002 * FullName.GetHashCode()
            hashCode += 1000000003 * Address.GetHashCode()
            hashCode += 1000000004 * ContactNumber.GetHashCode()
            hashCode += 1000000005 * CellPhone.GetHashCode()
            Return hashCode
        End Function

        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            Dim other As Employee = TryCast(obj, Employee)
            If other Is Nothing Then
                Return False
            End If

            Return UniqueCode = other.UniqueCode
        End Function

#End Region

    End Class
End Namespace
